#ifndef _GENERIC_BOX_MODEL_H_JM_20110828_
#define _GENERIC_BOX_MODEL_H_JM_20110828_
/// @file GenericBoxModel.h
/// _OK_ Sablona pre model boxu, ktory posobi v systeme bobox ako creator pre boxy.
#include <bobox_model.hpp>
#include <bobox_box.hpp>

#include "../runtime/BoxParameterPack.h"

namespace jm4bbx {

#ifdef BOBOX_VERSION_OLD

#ifndef GENERIC_BOX_MODEL_PARENT
/// Typ predka pre model boxu sa pre rozne verzie boboxu lisi, preto 
/// je doplneny preprocesorom podla makra GENERIC_BOX_MODEL_PARENT, ktore 
/// je definovane na zaklade verzie boboxu, s ktorym sa program preklada.
#define GENERIC_BOX_MODEL_PARENT bobox::box_model
#endif

#else

#ifndef GENERIC_BOX_MODEL_PARENT
/// Typ predka pre model boxu sa pre rozne verzie boboxu lisi, preto 
/// je doplneny preprocesorom podla makra GENERIC_BOX_MODEL_PARENT, ktore 
/// je definovane na zaklade verzie boboxu, s ktorym sa program preklada.
#define GENERIC_BOX_MODEL_PARENT bobox::basic_box_model
#endif

#endif

	/**
	* Sablona pre model boxu, ktory posobi v systeme bobox ako creator pre boxy.
	* Vacsine tried postacuje trivialny model/creator, ktory je vygenerovany 
	* na zaklade tejto sablony.
	* 
	* @tparam GeneratedBox typ generovaneho boxu
	**/
	template <class GeneratedBox> 
	class GenericBoxModel : public GENERIC_BOX_MODEL_PARENT {
	public:
		typedef GeneratedBox BoxType;

#ifdef BOBOX_VERSION_OLD

		GenericBoxModel(const BoxModelParamPack& p) : 
		GENERIC_BOX_MODEL_PARENT(p.id, p.tid, p.rt), params_(p.params) { }


		virtual bobox::box* create(bobox::box_id_type id, bobox::request* req) const {        
			return new GeneratedBox(BoxParamPack(id, tid_, params_, req));      
		}

#else
		GenericBoxModel(const BoxModelParamPack& p) : 
		GENERIC_BOX_MODEL_PARENT(p.modelPack) , params_(p.getPlainParameters()) { }

		virtual bobox::box_stateness_type get_stateness_type() const {
			return bobox::BST_STATEFUL; 
		}


		virtual bobox::box *create_impl(bobox::box_id_type id, 
			const bobox::box_tid_type &tid, bobox::box_pid_type pid, 
			const bobox::io_descriptors_type &input_descriptors, 
			const bobox::io_descriptors_type &output_descriptors, 
			bobox::plevel_type plevel, 
			const bobox::parameters_ptr_type &parameters, 
			bobox::request *req) const {

				bobox::box_parameters_pack bpp(id, tid, pid, req, input_descriptors, 
					output_descriptors);

				return new GeneratedBox(BoxParamPack(bpp, params_));
		}
#endif
	private:
		plainParameters params_;
	};

} // namespace jm4bbx

#endif
